package com.ailesson.video.controller;

import com.ailesson.video.model.reply.CoursePublishReply;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.ailesson.video.model.reply.CourseReply;
import com.ailesson.video.model.req.CourseReq;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import com.ailesson.video.service.CourseService;
import com.ailesson.video.model.req.CourseQueryReq;
import com.ailesson.common.reply.PageResult;
import com.ailesson.common.reply.R;



/**
 * 课程
 *
 * @author mac
 * @email mac@gmail.com
 * @date 2024-09-30 21:55:20
 */
@Tag(name = "课程模块")
@RestController
@RequestMapping("/admin/video/course")
public class CourseController {
    @Autowired
    private CourseService courseService;

    /**
     * 列表
     */
    @PostMapping("/list")
    @Operation(summary = "列表")
    @Parameter(name = "params", in = ParameterIn.DEFAULT, description = "查询参数")
   // @RequiresPermissions("video:course:list")
    public R list(@RequestBody CourseQueryReq params){
        PageResult page = courseService.queryPage(params);

        return R.success(page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    @Operation(summary = "获取信息")
    @Parameter(name = "id",in = ParameterIn.PATH, description = "ID")
   // @RequiresPermissions("video:course:info")
    public R info(@PathVariable("id") Long id){
		CourseReply course = courseService.info(id,true);

         return R.success(course);
    }

    /**
     * 保存
     */
    @PostMapping("/add")
    @Operation(summary = "添加")
    @Parameter(name = "teacher",in = ParameterIn.QUERY, description = "添加信息")
    //@RequiresPermissions("video:course:save")
    public R add(@RequestBody CourseReq course){
        return R.success(courseService.add(course));
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    @Operation(summary = "更新")
    @Parameter(name = "teacher",in = ParameterIn.QUERY, description = "更新信息")
    //@RequiresPermissions("video:course:update")
    public R update(@RequestBody CourseReq course){
		courseService.update(course);

        return R.success();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    @Operation(summary = "删除")
    @Parameter(name = "id",in = ParameterIn.PATH, description = "删除主键id")
    //@RequiresPermissions("video:course:delete")
    public R deleteById(@RequestBody Long id){
		courseService.deleteById(id);
        return R.success();
    }

    //根据课程id查询发布课程信息
    @Operation(summary = "id查询发布课程信息")
    @Parameter(name = "id",in = ParameterIn.PATH, description = "课程主键id")
    @GetMapping("/publish/query/{id}")
    public R getCoursePublishVo(@PathVariable Long id) {
        CoursePublishReply coursePublishVo = courseService.getCoursePublishById(id);
        return R.success(coursePublishVo);
    }

    //课程最终发布
    @Operation(summary = "课程最终发布")
    @Parameter(name = "id",in = ParameterIn.PATH, description = "课程主键id")
    @PutMapping("/publish/{id}")
    public R publishCourse(@PathVariable Long id) {
        courseService.publishCourse(id);
        return R.success();
    }


}
